#人脸检测
#A1面部检测
import requests
import json
subscription_key = "3a2d05b4b2224fdc84753d9d980ff89b"
assert subscription_key
face_api_url = 'https://zhichaorenlianshibie.cognitiveservices.azure.com/face/v1.0/detect'
image_url = 'http://newmedia.nfu.edu.cn/wcy/wp-content/uploads/2018/04/post_20180424__NFU_DoraHacks_imoji%E5%9B%A2%E9%98%9F.jpg'
headers = {'Ocp-Apim-Subscription-Key': subscription_key}
params = {
    'returnFaceId': 'true',
    'returnFaceLandmarks': 'false',
    'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise',
}

response = requests.post(face_api_url, params=params,
                         headers=headers, json={"url": image_url})

#A2json转译
results = response.json()
results

#A3pandas数据表格化
import pandas as pd
df_face = pd.json_normalize(results)
df_face

#A4数据取值
faceID = df_face['faceId'].values.tolist()
faceID

df_face.columns

df_face[['faceId','faceAttributes.glasses','faceAttributes.emotion.neutral','faceAttributes.age','faceAttributes.gender']]                         